/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.reduce.klsh.kmeaning.reducers;

import aiaudio.processing.reduce.klsh.kmeaning.DictionaryCoordinatePair;
import aiaudio.database.tables.ReduceResultTable;
import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;

/**
 *
 * @author nastya
 */
public class KMeansAlgorithmReducer extends TableReducer<ImmutableBytesWritable, DictionaryCoordinatePair, ImmutableBytesWritable> {

    @Override
    protected void reduce(ImmutableBytesWritable key, Iterable<DictionaryCoordinatePair> values, Context context) throws IOException, InterruptedException {
        Put put = new Put(key.get());
        for (DictionaryCoordinatePair dictionaryCoordinatePair : values) {            
            ReduceResultTable.addCoordinateInDictionary(put, dictionaryCoordinatePair.getDictionaryNumBytes(), 
                    dictionaryCoordinatePair.getCoordinateNumBytes(), dictionaryCoordinatePair.getDistanceBytes());
        }
        context.write(key, put);
    }
}
